package com.grechur.wanandroidcompose.repository

import android.text.TextUtils
import com.grechur.wanandroidcompose.bean.project.ProjectInfo
import com.grechur.wanandroidcompose.http.NetworkRequest
import kotlinx.coroutines.Dispatchers

class ProjectRepository : BaseRepository() {
//    fun getProjectTitles() = fire(Dispatchers.IO) {
//        val projectTitles = NetworkRequest.getProjectTitles()
//        if (projectTitles != null && projectTitles.errorCode == 0) {
//            projectTitles.data.takeIf { it != null }?.let { projectInfos: List<ProjectInfo> ->
//                Result.success(projectInfos)
//            }?: Result.failure(RuntimeException("getNews response code is ${projectTitles?.errorCode} msg is ${projectTitles?.errorMsg}"))
//        } else Result.failure(RuntimeException("getNews response code is ${projectTitles?.errorCode} msg is ${projectTitles?.errorMsg}"))
//    }
//
//    fun getProjectArticles(index:Int? = 1,cid:String?) = fire(Dispatchers.IO) {
//        if (TextUtils.isEmpty(cid)) {
//            return@fire Result.failure(IllegalArgumentException("cid is null"))
//        }
//        val projectArticles = NetworkRequest.getProjectArticles(index, cid)
//        if (projectArticles != null && projectArticles.errorCode == 0) {
//            Result.success(projectArticles)
//        } else {
//            Result.failure(RuntimeException("getNews response code is ${projectArticles?.errorCode} msg is ${projectArticles?.errorMsg}"))
//        }
//    }
}